package com.fyp.client.ptma;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.Window;
import android.widget.Toast;

public abstract class AbstractActivity extends Activity
{
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);

		super.onCreate(savedInstanceState);
		setContentView(getContentView());
		initViewRefereces();
	}

	void showLongToast(String message)
	{

		Toast.makeText(this, message, Toast.LENGTH_LONG).show();
	}

	void showShortToast(String message)
	{

		Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
	}

	void switchScreen(Class toActivity, Object data)
	{

		CustomIntent intent = new CustomIntent(this, toActivity);
		intent.putExtra("dataToCarry", data);
		this.startActivity(intent);
	}

	public static String getVersionByPackage(String pkg, Context ctx)
	{
		PackageInfo pInfo = null;
		String ver = null;
		try
		{
			pInfo = ctx.getPackageManager().getPackageInfo(pkg, 0);
			ver = pInfo.versionName;
		} catch (NameNotFoundException e)
		{
			ver = null;

		}

		return ver;
	}

	abstract int getContentView();

	abstract void initViewRefereces();
}
